package com.treeroot.gatewayservice.gateway.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
import org.springframework.web.util.pattern.PathPatternParser;


/**
 * <p>
 * 处理跨域
 * </p>
 */


@Configuration
public class CorsConfig {
    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration config = new CorsConfiguration();
//       允许https和hppt
        config.addAllowedMethod("*");
//      运行添加所有原点
        config.addAllowedOrigin("*");
//      添加实际请求标头以允许。
        config.addAllowedHeader("*");

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
//        在所有的路径模式上注册CorsConfiguration。
        source.registerCorsConfiguration("/**", config);

        return new CorsWebFilter(source);
    }
}

